#ifndef __REDISEXCEPTION_H__
#define __REDISEXCEPTION_H__
#include <functional>
#include <stdexcept>
#include <string>

enum class RedisErrno : int
{
    kOK = 0,
    kUnknown,
    kConnectionLost,
    kConnectionUnavailable,
    kRedisError,
    kInternalError,
    kTransactionCancelled,
    kBadType,
    kTimeout
};

class RedisException : public std::exception
{
  public:
    RedisException(RedisErrno code, std::string msg)
        : errmsg_(std::move(msg)), redisErrno_(code)
    {
    }

    RedisException() = delete;

    const char* what() const noexcept override
    {
        return errmsg_.c_str();
    }

    RedisErrno code() const
    {
        return redisErrno_;
    }

  protected:
    std::string errmsg_;
    RedisErrno redisErrno_{RedisErrno::kOK};
};

using RedisExceptionCallback_t = std::function<void(const RedisException&)>;

#endif  // __REDISEXCEPTION_H__